﻿@model qltscd.Models.ScreenClient.DanhMucHangSanXuatScreenClient

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/Modules/_LayoutDanhMucNhapLieu.cshtml";
}
<script type="text/javascript">
    function confirmXoa() {
        var idHSX = document.getElementById('idHSX').value;
        if (idHSX == null || idHSX == '-1') {
            alert("Chọn hãng sản xuất trước");
        } else {
            if (confirm("Bạn có muốn xóa hãng sản xuất này?")) {
                document.location = "/QuanLyThietBi/DanhMucHangSanXuat/XoaHangSanXuat?id=" + idHSX;
            }
        }
    }

    function confirmSua() {
        var idHSX = document.getElementById('idHSX').value;
        if (idHSX == null || idHSX == '-1') {
            alert("Chọn hãng sản xuất trước");
        } else {
            document.location = "/QuanLyThietBi/DanhMucHangSanXuat/SuaHangSanXuat?id=" + idHSX;
        }
    }

    function onCheck(id) {
        document.getElementById('idHSX').value = id;
    }
</script>

<h2>Hãng sản xuất</h2>
@{ Html.BeginForm(); }
<input type="hidden" value="-1" id="idHSX" name="idHSX"/>
@{
    Html.Telerik().Grid(Model.DanhMucHangSanXuats)
    .Name("grdDSHSX")
    .DataKeys(keys => keys.Add(c => c.IdentityHangSanXuat))
    .Resizable(r => r.Columns(true))
    .Reorderable(r => r.Columns(true))
    .Sortable()
    .Pageable(paging => paging.Enabled(true).Style(GridPagerStyles.NextPreviousAndInput).PageSize(15))
    //.Editable(editing => editing.Mode(GridEditMode.InCell))
    .ToolBar(t => {
        t.Custom()
            .Action("Create", "DanhMucHangSanXuat")
            .ButtonType(GridButtonType.ImageAndText)
            .ImageHtmlAttributes(new { @class = "t-icon t-add" })
            .Text("Thêm hãng");
        //t.SubmitChanges().ButtonType(GridButtonType.ImageAndText).SaveText("Lưu").CancelText("Hủy bỏ");
        t.Custom()
           .Text("Xóa hãng")
           .Url("#")
           .HtmlAttributes(new { @onclick = "confirmXoa()" })
           .ButtonType(GridButtonType.ImageAndText)
           .ImageHtmlAttributes(new { @style = "background-image: url('./../../../../../QuanLyThietBi/Content/Images/cross.png')" });
        t.Custom()
           .Text("Sửa hãng")
           .Url("#")
           .HtmlAttributes(new { @onclick = "confirmSua()" })
           .ButtonType(GridButtonType.ImageAndText)
           .ImageHtmlAttributes(new { @style = "background-image: url('./../../../../../QuanLyThietBi/Content/Images/hammer.png')" });
        t.Custom()
            .Text("In PDF")
            .Action("ShowPdf", "DanhMucHangSanXuat")
            .ButtonType(GridButtonType.ImageAndText)
            .ImageHtmlAttributes(new {
                @style = "background-image: url('./../../../../QuanLyThietBi/Content/Images/printer.png');"
            });
        t.Custom()
            .Text("Xuất Excel")
            .Action("ExportToExcel", "DanhMucHangSanXuat")
            .ButtonType(GridButtonType.ImageAndText)
            .ImageHtmlAttributes(new
            {
                @style = "background-image: url('./../../../../QuanLyThietBi/Content/Images/printer.png');"
            });
    })
    .DataBinding(databinding => {
        databinding.Server()
            .Select("Index", "DanhMucHangSanXuat");
        databinding.Ajax()
            .Select("_Index", "DanhMucHangSanXuat")
            .Insert("_Insert", "DanhMucHangSanXuat")
            .Delete("_Delete", "DanhMucHangSanXuat")
            .Update("_Update", "DanhMucHangSanXuat");
    })
    .Columns(column => {
        column.Template(@<text>
    <input name = "checkedRecords" type = "radio" title="Chọn" value="@item.IdentityHangSanXuat" onclick="onCheck(@item.IdentityHangSanXuat)"/>
    </text>)
               .ClientTemplate("<input type = 'radio' name = 'checkedRecords' value='<#=IdentityHangSanXuat#>' onclick='onCheck(<#=IdentityHangSanXuat#>)' />")
               .Title("").Width(50);
                column.Bound(o => o.MaHangSanXuat).Title("Mã Hãng Sản Xuất")
                @*.Template(@<text> <span onclick="openDetailsWindow('@item.IdentityHangSanXuat')">@item.MaHangSanXuat</span>
    </text>)
            .ClientTemplate("<span onclick='openDetailsWindow('<#=IdentityHangSanXuat#>')'><#=MaHangSanXuat#></span>")*@
            .Title("Mã Hãng Sản Xuất").Width(50);
                column.Bound(o => o.TenHangSanXuat).Title("Tên Hãng Sản Xuất");
                column.Bound(o => o.TrangWeb).Title("Trang Web");
                //column.Command(c => {
                //    c.Custom("Delete")
                //    .ButtonType(GridButtonType.Image)
                //    .Action("Delete", "DanhMucNhaCungCap")
                //    .ImageHtmlAttributes(new { @class = "t-icon t-delete" });     
                //}).Width(50);
    })
    .Render();
    }
    <script type="text/javascript">
        function openDetailsWindow(id) {
            var url = "/QuanLyThietBi/DanhMucHangSanXuat/ThongTinHangSanXuat/" + id;
            var windowElement = $.telerik.window.create({
                title: 'Thông tin hãng sản xuất',
                actions: ["Refresh", "Maximize", "Close"],
                contentUrl: url,
                modal: true,
                resizable: true,
                draggable: true,
                scrollable: true,
                visible: false,
                width: 1000,
                height: 650,
                id: 'detailsview',
                name: 'detailsview',
                onClose: function () {
                    document.location = document.location;
                }
            });
            var w = $(windowElement).data("tWindow");
            w.center();
            w.open();
        }
</script>

